export const getDays = function(d = "") {
  //本月第一天
  function showFirstDay(d) {
    var Nowdate = new Date(d);
    var MonthFirstDay = new Date(
      Nowdate.getYear(),
      Nowdate.getMonth(),
      1
    ).getDate();
    return MonthFirstDay;
  }
  //本月最后一天
  function showLastDay(d) {
    var Nowdate = new Date(d);
    var tmpDate = new Date(Nowdate.getYear(), Nowdate.getMonth() + 1, 1);
    var MonthLastDay = new Date(tmpDate - 86400000).getDate();
    return MonthLastDay;
  }
  var last = showLastDay(d);
  var start = showFirstDay(d);
  var date = new Date(d);
  var a = new Array();
  for (var i = start; i <= last; i++) {
    a[i - 1] = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + i;
  }
  var res = {
    firstDay: showFirstDay(d),
    lastDay: showLastDay(d),
    allDay: a
  };
  return res;
};

export async function callMethodLimitPage(fn, param, pageIndex, arr) {
  let pageSizeMax = 40;
  // if (param.pageSize && param.pageSize > 100) {
  //   pageSizeMax = param.pageSize
  // }
  const res = await fn({
    CMSearchDescription: {
      ...param.CMSearchDescription,
      searchResultPostion: pageIndex,
      maxResults: pageSizeMax
    }
    // maxResults: maxResults,
    // searchResultPostion: searchResultPostion,
  });
  const { numResults, results } = res;
  const dataClone = results || [];
  if (numResults !== 0 && results.length !== 0) {
    return callMethodLimitPage(fn, param, pageIndex + 20, [
      ...arr,
      ...dataClone
    ]);
  }
  return new Promise(resolve => {
    resolve([...arr, ...dataClone].length ? [...arr, ...dataClone] : []);
    // resolve({
    //   data: [...arr, ...dataClone].length ? [...arr, ...dataClone] : [],
    //   errorCode: 0,
    //   errorDesc: "success",
    //   totalCount: [...arr, ...dataClone].length
    // });
  });
}
